import { getJwt } from "@/utils/storage"
import { LoginPath } from "./routes"
import { Navigate, useLocation } from "react-router-dom"
import { FC, memo, ReactNode } from "react"


interface IProps {
    children?: ReactNode
  }
  
  const Intercept: FC<IProps> = ({ children }) => {
    const { pathname } = useLocation()
    const token = getJwt()
    if (!token && pathname !== LoginPath) {
      return <Navigate to={LoginPath} />
    }
    if(token&&pathname===LoginPath){
        return <Navigate to="/" />  
    }
    return children
  }
  
  export default memo(Intercept)